<template>
  <div class="Standard_management">
    <div class="pubBig Privilege">
      <div class="h0">
        <p class="lt"></p>
      </div>
      <div class="dDownMain">
        <div
          class="twoBox"
          :style="this.$route.query.Token ? 'top:50px;left:10px' : 'top: 100px'"
        >
          <el-row>
            <el-col :span="4">
              <el-tree
                :data="data"
                :props="defaultProps"
                @node-click="handleNodeClick"
                accordion
                class="leftTreeStyle"
                :style="left_tree"
                :highlight-current="true"
              ></el-tree>
            </el-col>
            <el-col :span="20" v-if="isShow == true" style="padding: 15px">
              <h3>{{ isTree_flag }}字段管理配置</h3>
              <template>
                <el-table
                  :data="tableData"
                  style="width: 100%"
                  height="740px"
                  v-loading="isTableData_loading"
                >
                  <el-table-column prop="ElementName" label="标准字段名">
                  </el-table-column>
                  <el-table-column prop="ElementCode" label="标准字段">
                  </el-table-column>
                  <el-table-column prop="IsProperty" label="是否为属性">
                    <template slot-scope="scope">
                      {{ scope.row.IsProperty == true ? "是" : "否" }}
                    </template>
                  </el-table-column>
                  <el-table-column prop="IsCanLoop" label="循环字段">
                    <template slot-scope="scope">
                      {{ scope.row.IsCanLoop == true ? "是" : "否" }}
                    </template>
                  </el-table-column>
                  <el-table-column prop="IsAllowNull" label="是否允许为空">
                    <template slot-scope="scope">
                      {{ scope.row.IsAllowNull == true ? "是" : "否" }}
                    </template>
                  </el-table-column>
                  <el-table-column prop="AssetCode" label="数据集编码">
                  </el-table-column>
                  <el-table-column prop="Value" label="数据元内部标识">
                  </el-table-column>
                  <el-table-column prop="ElementDesc" label="说明">
                  </el-table-column>
                  <!-- <el-table-column
                    prop="DocumentPartType"
                    label="标准字段的值域类型"
                  >
                  </el-table-column> -->
                  <el-table-column label="操作">
                    <template slot-scope="scope">
                      <el-button
                        size="mini"
                        icon="el-icon-edit"
                        @click="edit_one(scope.row)"
                      ></el-button>
                      <el-button
                        size="mini"
                        icon="el-icon-delete"
                        @click="del_one(scope.row.Id)"
                      ></el-button>
                    </template>
                  </el-table-column>
                </el-table>
              </template>
            </el-col>
            <el-col :span="20" v-if="isShow == false">
              <el-row>
                <el-col :span="5">
                  <!-- 临时操作按钮 -->
                  <el-button
                    icon="el-icon-plus"
                    size="mini"
                    style="margin: 10px"
                    @click="setoption(), open(1)"
                    >新加首级</el-button
                  >
                  <!-- 临时操作按钮 -->
                  <el-tree
                    :data="tree_List"
                    :props="defaultProps_right"
                    @node-click="handleNodeClick_infor"
                    accordion
                    class="RightTreeStyle"
                    :style="right_tree"
                    v-loading="isTree_loading"
                    :highlight-current="true"
                  >
                    <template slot-scope="obj">
                      <div
                        :title="
                          obj.data.IsWarning ? obj.data.WarningMessage : ''
                        "
                      >
                        <div
                          class="tree_itemStyle"
                          style="
                            display: inline-block;
                            width: 100px;
                            height: 20px;
                            line-height: 28px;
                          "
                        >
                          {{ obj.data.ElementName }}
                          <i
                            v-if="obj.data.IsWarning ? true : false"
                            class="el-icon-message-solid"
                            style="padding-left: 10px"
                          ></i>
                        </div>

                        <!-- 临时操作按钮开始 -->
                        <el-button
                          type="text"
                          icon="el-icon-plus"
                          style="padding-left: 30px"
                          size="mini"
                          @click="add_tree(obj.data)"
                        ></el-button>
                        <el-button
                          type="text"
                          icon="el-icon-edit"
                          size="mini"
                          @click="edit_tree(obj.data)"
                        ></el-button>
                        <el-button
                          type="text"
                          icon="el-icon-delete"
                          size="mini"
                          @click="del_tree(obj.data.Id)"
                        ></el-button>
                        <!-- 临时操作按钮结束 -->
                      </div>
                    </template>
                  </el-tree>
                </el-col>
                <el-col :span="19">
                  <div>
                    <span
                      style="
                        display: inline-block;
                        margin: 20px;
                        font-weight: 700;
                      "
                      >当前元素名：<span style="color: red">{{
                        isTree_ElementDesc.ElementName
                      }}</span></span
                    >
                    <el-button
                      style="float: right; margin: 15px"
                      size="mini"
                      type="primary"
                      @click="Generate_Document"
                      >生成文档</el-button
                    >
                  </div>
                  <div style="margin-top: 80px">
                    <el-divider></el-divider>

                    <span style="display: block">* 节点配置</span>
                    <div
                      style="margin-left: 150px; margin-top: 20px"
                      class="PZstyle"
                    >
                      <div style="display: inline-block">
                        <span style="display: inline-block">节点描述：</span>
                      </div>
                      <el-input
                        type="textarea"
                        :rows="5"
                        style="display: inline-block; width: 80%"
                        size="mini"
                        placeholder=""
                        v-model="isTree_ElementDesc.ElementDesc"
                      ></el-input>
                    </div>
                    <div style="margin-left: 140px; margin-top: 10px">
                      <span>是否为变量：</span>
                      <el-switch
                        v-model="isTree_ElementDesc.IsParamValue"
                        active-color="rgb(64,158,255)"
                        inactive-color="#ccc"
                      >
                      </el-switch>
                    </div>
                    <!--sy do-->
                    <div style="margin-left: 140px; margin-top: 10px">
                      <span>是否为循环节点：</span>
                      <el-switch
                        v-model="isTree_ElementDesc.IsCanLoop"
                        active-color="rgb(64,158,255)"
                        inactive-color="#ccc"
                      >
                      </el-switch>
                    </div>
                    <div style="margin-left: 165px; margin-top: 10px">
                      <span>节点值：</span>
                      <el-input
                        v-model="isTree_ElementDesc.Value"
                        style="display: inline-block; width: 80%"
                      >
                      </el-input>
                    </div>
                  </div>
                  <div>
                    <!-- 临时操作按钮 -->
                    <el-button
                      icon="el-icon-plsh"
                      @click="add_table"
                      style="margin-left: 20px; margin-bottom: -30px"
                      >新增属性</el-button
                    >
                    <template>
                      <el-table
                        :data="tableData_treeItem"
                        border
                        style="width: 100%; margin-top: 40px"
                        v-loading="isTableData_Right"
                        height="200px"
                      >
                        <el-table-column
                          prop="ElementName"
                          label="属性值"
                          align="center"
                        >
                        </el-table-column>
                        <el-table-column
                          prop="IsParamValue"
                          label="是否为变量"
                          align="center"
                        >
                          <template slot-scope="scope">
                            <el-switch
                              v-model="scope.row.IsParamValue"
                              active-color="rgb(64,158,255)"
                              inactive-color="#ccc"
                            >
                            </el-switch>
                          </template>
                        </el-table-column>
                        <el-table-column
                          label="默认值"
                          align="center"
                          prop="Value"
                        >
                          <template slot-scope="scope">
                            <el-input
                              v-model="scope.row.Value"
                              size="mini"
                            ></el-input>
                          </template>
                        </el-table-column>
                        <el-table-column width="60" fixed="right" label="操作">
                          <template slot-scope="scope">
                            <el-button
                              size="mini"
                              @click="del_table(scope.row.Id)"
                              icon="el-icon-delete"
                            ></el-button>
                          </template>
                        </el-table-column>
                      </el-table>
                    </template>
                  </div>
                  <div style="text-align: center; margin-top: 15px">
                    <el-button size="mini" type="primary" @click="btn_Ok_right"
                      >保存</el-button
                    >
                    <el-button size="mini" v-if="false">重置</el-button>
                  </div>
                </el-col>
              </el-row>
            </el-col>
          </el-row>
          <el-dialog
            title="更新字段"
            :visible.sync="dialogVisible"
            width="45%"
            :before-close="handleClose"
            :close-on-click-modal="false"
            :append-to-body="true"
          >
            <el-form
              label-position="right"
              label-width="120px"
              :model="formLabelAlign"
            >
              <el-form-item
                label="标准字段名"
                style="width: 50%; display: inline-block"
              >
                <el-input
                  disabled
                  v-model="formLabelAlign.ElementName"
                ></el-input>
              </el-form-item>
              <el-form-item
                label="标准字段"
                style="width: 50%; display: inline-block"
              >
                <el-input
                  disabled
                  v-model="formLabelAlign.ElementCode"
                ></el-input>
              </el-form-item>
              <el-form-item
                label="数据集编码"
                style="width: 50%; display: inline-block"
              >
                <el-input disabled v-model="formLabelAlign.AssetCode">
                </el-input>
              </el-form-item>
              <el-form-item
                label="数据元内部标识"
                style="width: 50%; display: inline-block"
              >
                <el-input v-model="formLabelAlign.Value">
                  <el-button
                    slot="append"
                    icon="el-icon-s-unfold"
                    @click="getCodeList(formLabelAlign.ElementCode)"
                  ></el-button>
                </el-input>
              </el-form-item>
              <el-form-item
                label="是否为属性"
                style="width: 50%; display: inline-block"
              >
                <el-select
                  filterable
                  v-model="formLabelAlign.IsProperty"
                  placeholder="请选择"
                  style="width: 100%"
                >
                  <el-option label="是" :value="true"> </el-option>
                  <el-option label="否" :value="false"> </el-option>
                </el-select>
              </el-form-item>
              <el-form-item
                label="循环字段"
                style="width: 50%; display: inline-block"
              >
                <el-select
                  filterable
                  v-model="formLabelAlign.IsCanLoop"
                  placeholder="请选择"
                  style="width: 100%"
                >
                  <el-option label="是" :value="true"> </el-option>
                  <el-option label="否" :value="false"> </el-option>
                </el-select>
              </el-form-item>
              <el-form-item
                label="是否允许为空"
                style="width: 50%; display: inline-block"
              >
                <el-select
                  filterable
                  v-model="formLabelAlign.IsAllowNull"
                  placeholder="请选择"
                  style="width: 100%"
                >
                  <el-option label="是" :value="true"> </el-option>
                  <el-option label="否" :value="false"> </el-option>
                </el-select>
              </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
              <el-button @click="handleClose">取 消</el-button>
              <el-button type="primary" @click="btn_Ok">确 定</el-button>
            </span>
          </el-dialog>
          <el-dialog
            title="选择字段值"
            :visible.sync="dialogVisible_valueList"
            width="45%"
            :close-on-click-modal="false"
            :before-close="handleClose_valueList"
            :append-to-body="true"
            stripe
          >
            <el-table
              :data="hsValueList"
              style="width: 100%"
              :default-sort="{ prop: 'InternalCode' }"
              @row-dblclick="handleSelectionValue"
            >
              <el-table-column sortable prop="InternalCode" label="内部标识符">
              </el-table-column>
              <el-table-column sortable prop="AssetCode" label="数据集编码">
              </el-table-column>
              <el-table-column sortable prop="FormName" label="数据集">
              </el-table-column>
              <el-table-column sortable prop="ElementName" label="数据元名称">
              </el-table-column>
              <el-table-column sortable prop="Define" label="描述">
              </el-table-column>
            </el-table>
          </el-dialog>
        </div>
      </div>
    </div>
    <!-- 临时弹层 -->
    <el-dialog
      title="操作"
      :visible.sync="dialogVisible_add"
      width="45%"
      :before-close="handleClose_add"
      :append-to-body="true"
      :close-on-click-modal="false"
    >
      <el-form
        label-position="right"
        label-width="120px"
        :model="formLabelAlign_add"
      >
        <el-form-item
          label="元素标识"
          style="width: 50%; display: inline-block"
        >
          <el-input v-model="formLabelAlign_add.ElementCode"></el-input>
        </el-form-item>
        <el-form-item
          label="元素名称"
          style="width: 50%; display: inline-block"
        >
          <el-input v-model="formLabelAlign_add.ElementName"></el-input>
        </el-form-item>
        <el-form-item
          label="元素描述"
          style="width: 100%; display: inline-block"
        >
          <el-input
            type="textarea"
            :rows="2"
            v-model="formLabelAlign_add.ElementDesc"
          ></el-input>
        </el-form-item>
        <el-form-item label="排序" style="width: 50%; display: inline-block">
          <el-input v-model="formLabelAlign_add.Sort"></el-input>
        </el-form-item>
        <el-form-item label="变量" style="width: 50%; display: inline-block">
          <el-radio-group v-model="formLabelAlign_add.IsParamValue">
            <el-radio :label="true">是</el-radio>
            <el-radio :label="false">否</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="节点值" style="width: 50%; display: inline-block">
          <el-input v-model="formLabelAlign_add.Value"></el-input>
        </el-form-item>
        <el-form-item
          label="所属文档"
          style="width: 50%; display: inline-block"
          v-if="isShowFlag"
        >
          <el-radio-group v-model="formLabelAlign_add.DocumentPartType">
            <el-radio label="DocumentHeader">文档头</el-radio>
            <el-radio label="DocumentBody">文档体</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item
          label="表名"
          style="width: 50%; display: inline-block"
          v-if="isShowFlag"
        >
          <el-input v-model="formLabelAlign_add.TableName"></el-input>
        </el-form-item>
        <el-form-item
          label="基数"
          style="width: 50%; display: inline-block"
          v-if="isShowFlag"
        >
          <el-input v-model="formLabelAlign_add.BaseNum"></el-input>
        </el-form-item>
        <el-form-item
          label="循环"
          style="width: 50%; display: inline-block"
          v-if="isShowFlag"
        >
          <el-radio-group v-model="formLabelAlign_add.IsCanLoop">
            <el-radio :label="true">是</el-radio>
            <el-radio :label="false">否</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item
          label="缺省"
          style="width: 50%; display: inline-block"
          v-if="isShowFlag"
        >
          <el-radio-group v-model="formLabelAlign_add.IsAllowNull">
            <el-radio :label="true">是</el-radio>
            <el-radio :label="false">否</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item
          label="是否是节点属性"
          style="width: 50%; display: inline-block"
          v-show="false"
        >
          <el-radio-group v-model="formLabelAlign_add.IsProperty">
            <el-radio :label="true">属性</el-radio>
            <el-radio :label="false">节点</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item
          label="节点级别"
          style="width: 50%; display: inline-block"
          v-if="false"
        >
          <el-input
            placeholder="节点级别 属性级别 -1 节点级别 1 - 6 "
            v-model="formLabelAlign_add.Level"
          ></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="handleClose_add">取 消</el-button>
        <el-button type="primary" @click="list_ToDo">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: "",
  data() {
    return {
      data: [
        {
          label: "EMR01(病历概要)",
          flag: "EMR01",
          children: [
            { label: "字段管理配置", val: 1 },
            { label: "文档结构配置", val: 2 },
          ],
        },
        {
          label: "EMR02(门(急)诊病历)",
          flag: "EMR02",
          children: [
            { label: "字段管理配置", val: 1 },
            { label: "文档结构配置", val: 2 },
          ],
        },
        {
          label: "EMR03(急诊留观病历)",
          flag: "EMR03",
          children: [
            { label: "字段管理配置", val: 1 },
            { label: "文档结构配置", val: 2 },
          ],
        },
        {
          label: "EMR04(西药处方)",
          flag: "EMR04",
          children: [
            { label: "字段管理配置", val: 1 },
            { label: "文档结构配置", val: 2 },
          ],
        },
        {
          label: "EMR05(中药处方)",
          flag: "EMR05",
          children: [
            { label: "字段管理配置", val: 1 },
            { label: "文档结构配置", val: 2 },
          ],
        },
        {
          label: "EMR06(检查报告)",
          flag: "EMR06",
          children: [
            { label: "字段管理配置", val: 1 },
            { label: "文档结构配置", val: 2 },
          ],
        },
        {
          label: "EMR07(检验报告)",
          flag: "EMR07",
          children: [
            { label: "字段管理配置", val: 1 },
            { label: "文档结构配置", val: 2 },
          ],
        },
        {
          label: "EMR08(治疗记录)",
          flag: "EMR08",
          children: [
            { label: "字段管理配置", val: 1 },
            { label: "文档结构配置", val: 2 },
          ],
        },
        {
          label: "EMR09(一般手术记录)",
          flag: "EMR09",
          children: [
            { label: "字段管理配置", val: 1 },
            { label: "文档结构配置", val: 2 },
          ],
        },
        {
          label: "EMR10(麻醉术前访视记录)",
          flag: "EMR10",
          children: [
            { label: "字段管理配置", val: 1 },
            { label: "文档结构配置", val: 2 },
          ],
        },
        {
          label: "EMR11(麻醉记录)",
          flag: "EMR11",
          children: [
            { label: "字段管理配置", val: 1 },
            { label: "文档结构配置", val: 2 },
          ],
        },
        {
          label: "EMR12(麻醉术后访视记录)",
          flag: "EMR12",
          children: [
            { label: "字段管理配置", val: 1 },
            { label: "文档结构配置", val: 2 },
          ],
        },
        {
          label: "EMR13(输血记录)",
          flag: "EMR13",
          children: [
            { label: "字段管理配置", val: 1 },
            { label: "文档结构配置", val: 2 },
          ],
        },
        {
          label: "EMR14(待产记录)",
          flag: "EMR14",
          children: [
            { label: "字段管理配置", val: 1 },
            { label: "文档结构配置", val: 2 },
          ],
        },
        {
          label: "EMR15(阴道分娩记录)",
          flag: "EMR15",
          children: [
            { label: "字段管理配置", val: 1 },
            { label: "文档结构配置", val: 2 },
          ],
        },
        {
          label: "EMR16(剖宫产记录)",
          flag: "EMR16",
          children: [
            { label: "字段管理配置", val: 1 },
            { label: "文档结构配置", val: 2 },
          ],
        },
        {
          label: "EMR17(一般护理记录)",
          flag: "EMR17",
          children: [
            { label: "字段管理配置", val: 1 },
            { label: "文档结构配置", val: 2 },
          ],
        },
        {
          label: "EMR18(病重（病危）护理记录)",
          flag: "EMR18",
          children: [
            { label: "字段管理配置", val: 1 },
            { label: "文档结构配置", val: 2 },
          ],
        },
        {
          label: "EMR19(手术护理记录)",
          flag: "EMR19",
          children: [
            { label: "字段管理配置", val: 1 },
            { label: "文档结构配置", val: 2 },
          ],
        },
        {
          label: "EMR20(生命体征测量记录)",
          flag: "EMR20",
          children: [
            { label: "字段管理配置", val: 1 },
            { label: "文档结构配置", val: 2 },
          ],
        },
        {
          label: "EMR21(出入量记录)",
          flag: "EMR21",
          children: [
            { label: "字段管理配置", val: 1 },
            { label: "文档结构配置", val: 2 },
          ],
        },
        {
          label: "EMR22(高值耗材使用记录)",
          flag: "EMR22",
          children: [
            { label: "字段管理配置", val: 1 },
            { label: "文档结构配置", val: 2 },
          ],
        },
        {
          label: "EMR23(入院评估)",
          flag: "EMR23",
          children: [
            { label: "字段管理配置", val: 1 },
            { label: "文档结构配置", val: 2 },
          ],
        },
        {
          label: "EMR24(护理计划)",
          flag: "EMR24",
          children: [
            { label: "字段管理配置", val: 1 },
            { label: "文档结构配置", val: 2 },
          ],
        },
        {
          label: "EMR25(出院评估与指导)",
          flag: "EMR25",
          children: [
            { label: "字段管理配置", val: 1 },
            { label: "文档结构配置", val: 2 },
          ],
        },
        {
          label: "EMR26(手术知情同意书)",
          flag: "EMR26",
          children: [
            { label: "字段管理配置", val: 1 },
            { label: "文档结构配置", val: 2 },
          ],
        },
        {
          label: "EMR27(麻醉知情同意书)",
          flag: "EMR27",
          children: [
            { label: "字段管理配置", val: 1 },
            { label: "文档结构配置", val: 2 },
          ],
        },
        {
          label: "EMR28(输血治疗同意书)",
          flag: "EMR28",
          children: [
            { label: "字段管理配置", val: 1 },
            { label: "文档结构配置", val: 2 },
          ],
        },
        {
          label: "EMR29(特殊检查及特殊治疗同意书)",
          flag: "EMR29",
          children: [
            { label: "字段管理配置", val: 1 },
            { label: "文档结构配置", val: 2 },
          ],
        },
        {
          label: "EMR30(病危（重）通知书)",
          flag: "EMR30",
          children: [
            { label: "字段管理配置", val: 1 },
            { label: "文档结构配置", val: 2 },
          ],
        },
        {
          label: "EMR31(其他知情同意书)",
          flag: "EMR31",
          children: [
            { label: "字段管理配置", val: 1 },
            { label: "文档结构配置", val: 2 },
          ],
        },
        {
          label: "EMR32(住院病案首页)",
          flag: "EMR32",
          children: [
            { label: "字段管理配置", val: 1 },
            { label: "文档结构配置", val: 2 },
          ],
        },
        {
          label: "EMR33(中医住院病案首页)",
          flag: "EMR33",
          children: [
            { label: "字段管理配置", val: 1 },
            { label: "文档结构配置", val: 2 },
          ],
        },
        {
          label: "EMR34(入院记录)",
          flag: "EMR34",
          children: [
            { label: "字段管理配置", val: 1 },
            { label: "文档结构配置", val: 2 },
          ],
        },
        {
          label: "EMR35(24小时内入出院记录)",
          flag: "EMR35",
          children: [
            { label: "字段管理配置", val: 1 },
            { label: "文档结构配置", val: 2 },
          ],
        },
        {
          label: "EMR36(24小时内入院死亡记录)",
          flag: "EMR36",
          children: [
            { label: "字段管理配置", val: 1 },
            { label: "文档结构配置", val: 2 },
          ],
        },
        {
          label: "EMR37(住院病程记录 首次病程记录)",
          flag: "EMR37",
          children: [
            { label: "字段管理配置", val: 1 },
            { label: "文档结构配置", val: 2 },
          ],
        },
        {
          label: "EMR38(住院病程记录 日常病程记录)",
          flag: "EMR38",
          children: [
            { label: "字段管理配置", val: 1 },
            { label: "文档结构配置", val: 2 },
          ],
        },
        {
          label: "EMR39(住院病程记录-上级医师查房记录)",
          flag: "EMR39",
          children: [
            { label: "字段管理配置", val: 1 },
            { label: "文档结构配置", val: 2 },
          ],
        },
        {
          label: "EMR40(住院病程记录-疑难病例讨论记录)",
          flag: "EMR40",
          children: [
            { label: "字段管理配置", val: 1 },
            { label: "文档结构配置", val: 2 },
          ],
        },
        {
          label: "EMR41(住院病程记录-交接班记录)",
          flag: "EMR41",
          children: [
            { label: "字段管理配置", val: 1 },
            { label: "文档结构配置", val: 2 },
          ],
        },
        {
          label: "EMR42(住院病程记录-转科记录)",
          flag: "EMR42",
          children: [
            { label: "字段管理配置", val: 1 },
            { label: "文档结构配置", val: 2 },
          ],
        },
        {
          label: "EMR43(住院病程记录-阶段小结)",
          flag: "EMR43",
          children: [
            { label: "字段管理配置", val: 1 },
            { label: "文档结构配置", val: 2 },
          ],
        },
        {
          label: "EMR44(住院病程记录-抢救记录)",
          flag: "EMR44",
          children: [
            { label: "字段管理配置", val: 1 },
            { label: "文档结构配置", val: 2 },
          ],
        },
        {
          label: "EMR45(住院病程记录-会诊记录)",
          flag: "EMR45",
          children: [
            { label: "字段管理配置", val: 1 },
            { label: "文档结构配置", val: 2 },
          ],
        },
        {
          label: "EMR46(住院病程记录-术前小结)",
          flag: "EMR46",
          children: [
            { label: "字段管理配置", val: 1 },
            { label: "文档结构配置", val: 2 },
          ],
        },
        {
          label: "EMR47(住院病程记录-术前讨论)",
          flag: "EMR47",
          children: [
            { label: "字段管理配置", val: 1 },
            { label: "文档结构配置", val: 2 },
          ],
        },
        {
          label: "EMR48(住院病程记录-术后首次病程记录)",
          flag: "EMR48",
          children: [
            { label: "字段管理配置", val: 1 },
            { label: "文档结构配置", val: 2 },
          ],
        },
        {
          label: "EMR49(住院病程记录-出院记录)",
          flag: "EMR49",
          children: [
            { label: "字段管理配置", val: 1 },
            { label: "文档结构配置", val: 2 },
          ],
        },
        {
          label: "EMR50(住院病程记录-死亡记录)",
          flag: "EMR50",
          children: [
            { label: "字段管理配置", val: 1 },
            { label: "文档结构配置", val: 2 },
          ],
        },
        {
          label: "EMR51(住院病程记录-死亡病例讨论记录)",
          flag: "EMR51",
          children: [
            { label: "字段管理配置", val: 1 },
            { label: "文档结构配置", val: 2 },
          ],
        },
        {
          label: "EMR52(住院医嘱)",
          flag: "EMR52",
          children: [
            { label: "字段管理配置", val: 1 },
            { label: "文档结构配置", val: 2 },
          ],
        },
        {
          label: "EMR53(出院小结)",
          flag: "EMR53",
          children: [
            { label: "字段管理配置", val: 1 },
            { label: "文档结构配置", val: 2 },
          ],
        },
      ],

      defaultProps: {
        children: "children",
        label: "label",
      },
      defaultProps_right: {
        children: "Child",
        label: "ElementName",
      },
      isShow: null,
      tableData: [],
      dialogVisible: false,
      formLabelAlign: {},
      tableData_treeItem: [],
      isTree_flag: "",
      tree_List: [],
      isTree_ElementDesc: {},
      isTree_loading: false,
      isTableData_loading: false,
      isTableData_Right: false,
      // 临时
      dialogVisible_add: false, //临时弹层
      dialogVisible_valueList: false,
      formLabelAlign_add: {},
      isTree_label: "",
      isData: {},
      isJDSX: "",
      isShowFlag: true,
      right_tree: "", // 右侧树高度
      left_tree: "", // 左侧树高度
      hsValueList: [],
    };
  },
  methods: {
    handleNodeClick(data) {
      this.isData = data;
      this.tableData_treeItem = [];
      this.isTree_ElementDesc = {};
      if (data.flag) {
        console.log(data.flag);
        this.isTree_flag = data.flag;
        this.isTree_label = data.label;
        this.isShow = null;
      }
      if (data.val) {
        data.val == 1 ? (this.isShow = true) : (this.isShow = false);
        if (data.val == 1) {
          this.isTableData_loading = true;
          this.$post(
            "/DocumentManage/Standard/FieldList?documentCode=" +
              this.isTree_flag
          ).then((res) => {
            if (res.code == 0) {
              this.tableData = res.data;
              this.isTableData_loading = false;
            }
          });
        } else {
          this.isTree_loading = true;
          this.$post(
            "/DocumentManage/Standard/ConfigTree?documentCode=" +
              this.isTree_flag
          )
            .then((res) => {
              if (res.code == 0) {
                this.tree_List = res.data;
                this.isTree_loading = false;
              }
            })
            .catch((err) => {
              this.isTree_loading = false;
            });
        }
      }
    },
    edit_one(val) {
      var info = JSON.stringify(val);
      this.formLabelAlign = JSON.parse(info);
      this.dialogVisible = true;
    },
    del_one(id) {
      this.$confirm("确定删除?", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then((_) => {
          this.$post("/DocumentManage/Standard/Delete/" + id).then((res) => {
            if (res.code == 0) {
              this.handleNodeClick(this.isData);
              this.$message({
                message: "操作成功",
                type: "success",
              });
            }
          });
        })
        .catch((_) => {});
    },
    handleClose() {
      this.dialogVisible = false;
      this.formLabelAlign = {};
      this.isShowFlag = true;
    },
    handleNodeClick_infor(data) {
      // this.tableData_treeItem = data
      console.log(data);
      this.isJDSX = data.Code;
      this.isTree_ElementDesc = data;
      this.isTableData_Right = true;
      this.$post(
        "/DocumentManage/Standard/ConfigList?documentCode=" +
          this.isTree_flag +
          "&code=" +
          data.Code
      ).then((res) => {
        if (res.code == 0) {
          this.tableData_treeItem = res.data;
          this.isTableData_Right = false;
        }
      });
    },
    btn_Ok() {
      this.$post("/DocumentManage/Standard/Update", this.formLabelAlign).then(
        (res) => {
          if (res.code == 0) {
            this.handleClose();
            this.isTableData_loading = true;
            this.$post(
              "/DocumentManage/Standard/FieldList?documentCode=" +
                this.isTree_flag
            ).then((res) => {
              if (res.code == 0) {
                this.tableData = res.data;
                this.isTableData_loading = false;
              }
            });
            this.$message({
              message: "操作成功",
              type: "success",
            });
          } else if (res.code != 0) {
            this.$message.error(res.msg);
          }
        }
      );
    },
    btn_Ok_right() {
      let body = this.tableData_treeItem;
      if (body != undefined) {
        body.push({
          Id: this.isTree_ElementDesc.Id,
          ElementDesc: this.isTree_ElementDesc.ElementDesc,
          Value: this.isTree_ElementDesc.Value,
          IsParamValue: this.isTree_ElementDesc.IsParamValue,
        });
      } else {
        body = [
          {
            Id: this.isTree_ElementDesc.Id,
            ElementDesc: this.isTree_ElementDesc.ElementDesc,
            Value: this.isTree_ElementDesc.Value,
            IsParamValue: this.isTree_ElementDesc.IsParamValue,
          },
        ];
      }
      console.log(body);

      this.$post("/DocumentManage/Standard/BatchUpdate", body).then((res) => {
        if (res.code == 0) {
          // 刷新树
          // this.$post("/DocumentManage/Standard/ConfigTree?documentCode=" + this.isTree_flag).then(res => {
          //   if (res.code == 0) {
          //     this.tree_List = res.data
          //   }
          // })
          // 刷新表格
          this.isTableData_Right = true;
          this.$post(
            "/DocumentManage/Standard/ConfigList?documentCode=" +
              this.isTree_flag +
              "&code=" +
              this.isTree_ElementDesc.Code
          ).then((res) => {
            if (res.code == 0) {
              this.tableData_treeItem = res.data;
              this.isTableData_Right = false;
            }
          });
          this.$message({
            message: "操作成功",
            type: "success",
          });
        }
      });
    },
    Generate_Document() {
      // console.log(this.isTree_flag);
      this.$post(
        "/DocumentManage/Standard/CreateTemp?fileCode=" +
          this.isTree_flag +
          "&version=V1.0"
      ).then((res) => {
        if (res.code == 0) {
          // console.log(res.data);
          this.fileUrl(res.data);
        } else {
          this.$message.error(res.msg);
        }
      });
    },
    fileUrl(fdId) {
      if (fdId.indexOf('"') == 0) {
        fdId = fdId.substring(1, fdId.length); //去掉第一个 "
      }
      if (fdId.lastIndexOf('"') == fdId.length - 1) {
      }

      // console.log(fdId);
      // window.open(fdId)
      this.$router.push(fdId);
    },
    // 临时
    handleClose_add() {
      // 弹层关闭
      this.dialogVisible_add = false;
      this.formLabelAlign_add = {};
      this.isShowFlag = true;
    },
    handleClose_valueList() {
      this.dialogVisible_valueList = false;
    },
    list_ToDo() {
      // 弹层确定按钮
      this.formLabelAlign_add.DocumentCode = this.isTree_flag;
      this.formLabelAlign_add.DocumentName = this.isTree_label;
      let data = this.formLabelAlign_add;
      var url = this.formLabelAlign_add.Id
        ? "/DocumentManage/Standard/Update"
        : "/DocumentManage/Standard/Create";
      this.$post(url, data).then((res) => {
        if (res.code == 0) {
          if (!this.isShowFlag) {
            this.handleNodeClick_infor(this.isTree_ElementDesc);
          }
          if (this.isShowFlag) {
            this.handleNodeClick(this.isData);
          }
          this.$message({
            message: "操作成功",
            type: "success",
          });
          this.handleClose_add();
        } else {
          this.$message({
            message: res.msg,
            type: "error",
          });
        }
      });
    },
    open() {
      // 弹层开启
      this.dialogVisible_add = true;
    },
    del_tree(id) {
      this.$confirm("确定删除?", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then((_) => {
          this.$post("/DocumentManage/Standard/Delete/" + id).then((res) => {
            if (res.code == 0) {
              this.handleNodeClick(this.isData);
              this.$message({
                message: "操作成功",
                type: "success",
              });
            }
          });
        })
        .catch((_) => {});
    },
    del_table(id) {
      this.$confirm("确定删除?", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then((_) => {
          this.$post("/DocumentManage/Standard/Delete/" + id).then((res) => {
            if (res.code == 0) {
              this.handleNodeClick_infor(this.isTree_ElementDesc);
              this.$message({
                message: "操作成功",
                type: "success",
              });
            }
          });
        })
        .catch((_) => {});
    },
    edit_tree(val) {
      var info = JSON.stringify(val);
      this.formLabelAlign_add = JSON.parse(info);
      this.open();
    },
    add_tree(val) {
      console.log(val);
      this.formLabelAlign_add.ParentCode = val.Code;
      this.formLabelAlign_add.IsProperty = false;
      this.formLabelAlign_add.IsParamValue = false;
      this.formLabelAlign_add.DocumentPartType = "DocumentBody";
      this.formLabelAlign_add.IsCanLoop = false;
      this.formLabelAlign_add.IsAllowNull = false;
      this.open();
    },
    add_table() {
      this.isShowFlag = false;
      this.formLabelAlign_add.IsProperty = true;
      this.formLabelAlign_add.ParentCode = this.isJDSX;
      this.formLabelAlign_add.Level = -1;
      this.formLabelAlign_add.DocumentPartType = "DocumentBody";
      this.formLabelAlign_add.TableName = "";
      this.formLabelAlign_add.BaseNum = this.isTree_ElementDesc.ElementName;
      this.formLabelAlign_add.IsCanLoop = false;
      this.formLabelAlign_add.IsAllowNull = false;
      this.formLabelAlign_add.IsParamValue = false;
      this.open();
    },
    setoption() {
      this.formLabelAlign_add.IsProperty = false;
      this.formLabelAlign_add.IsParamValue = false;
      this.formLabelAlign_add.DocumentPartType = "DocumentBody";
      this.formLabelAlign_add.IsCanLoop = false;
      this.formLabelAlign_add.IsAllowNull = false;
    },
    getCodeList(data) {
      this.hsValueList = [];
      this.$post(
        "/DocumentManage/Standard/FieldListByElementCode?elementCode=" + data
      ).then((res) => {
        if (res.code == 0) {
          this.dialogVisible_valueList = true;
          this.hsValueList = res.data;
        }
      });
    },
    handleSelectionValue(row, column, event) {
      this.formLabelAlign.Value =
        "@" + row.InternalCode.toLowerCase().replace(/[.]/g, "");
      this.formLabelAlign.AssetCode = row.AssetCode;
      this.dialogVisible_valueList = false;
    },
  },
  mounted() {
    // document.getElementById("2").focus();
    // console.log(document.documentElement.clientWidth);
    // console.log(document.documentElement.clientHeight);
    this.right_tree =
      "height:" + (document.documentElement.clientHeight - 160) + "px";
    this.left_tree =
      "height:" + (document.documentElement.clientHeight - 110) + "px";
    // console.log(this.right_tree);
  },
  created() {
    if (this.$route.query.Token) {
      localStorage.setItem("Token", this.$route.query.Token);
    }
  },
};
</script>
<style lang="scss">
.Standard_management {
  .top-input {
    display: inline-block;
    width: 350px;
  }

  .box-top {
    margin-top: 15px;
    margin-left: 5px;
  }
  .leftTreeStyle {
    height: 800px;
    border-right: 1px solid #ccc;
    overflow: auto;
  }
  .RightTreeStyle {
    height: 750px;
    border-right: 1px solid #ccc;
    overflow-x: auto;
  }
  .PZstyle {
    display: flex;
    align-items: flex-start;
  }
  .tree_itemStyle {
    // width: 100%;
    // overflow: auto;
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
    word-break: break-all;
  }
  .el-scrollbar .el-scrollbar__wrap {
    overflow-x: auto;
  }
  .el-tree > .el-tree-node {
    min-width: 100%;
    display: inline-block;
  }
  ::-webkit-scrollbar {
    /*滚动条整体样式*/

    width: 5px; /*高宽分别对应横竖滚动条的尺寸*/

    height: 8px;
  }
}
</style>
